//
//  HHChatDetailDemoViewController.m
//  HHChatKit
//
//  Created by Henry on 2021/8/19.
//

#import "HHChatDetailDemoViewController.h"
#import <HHTool/HHTool.h>
#import "HHSelectUserDemoViewController.h"
#import "HHDeleteMemberDemoViewController.h"

@interface HHChatDetailDemoViewController ()

@end

@implementation HHChatDetailDemoViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupData];
}

- (void)setupData {
    
    XLFormDescriptor *form;
    XLFormSectionDescriptor *section;
    XLFormRowDescriptor *row;
    
    form = [XLFormDescriptor formDescriptor];
    section = [XLFormSectionDescriptor formSection];
    [form addFormSection:section];
    
    NSMutableArray *users = [NSMutableArray array];
    for (int i = 0; i < 50; i ++) {
        HHSelectUserModel *model = [[HHSelectUserModel alloc] init];
        model.userId = [NSString stringWithFormat:@"%d", i];
        model.name = [NSString stringWithFormat:@"姓名-%d", i];
        [users addObject:model];
    }
    
    HHDetailUserModel *userModel = [[HHDetailUserModel alloc] initWithData:users];
//    userModel.width = self.view.frame.size.width;
    userModel.addPermission = YES;
    userModel.deletePermission = YES;
    
    __weak typeof(self) ws = self;
    userModel.didSelectUser = ^(HHSelectUserModel * _Nonnull model) {
        if (model.selectType == HHSelectUserTypeDelete) {
                        
            HHDeleteMemberDemoViewController *vc = [[HHDeleteMemberDemoViewController alloc] init];
            UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
            nav.modalPresentationStyle = UIModalPresentationFullScreen;
            [ws presentViewController:nav animated:YES completion:nil];
            
        } else if (model.selectType == HHSelectUserTypeAdd) {
            HHSelectUserDemoViewController *vc = [[HHSelectUserDemoViewController alloc] init];
            UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
            nav.modalPresentationStyle = UIModalPresentationFullScreen;
            [ws presentViewController:nav animated:YES completion:nil];
        } else {
            [HHToastTool show:model.name];
        }
    };
    userModel.didSelectMore = ^(NSArray * _Nonnull data) {
        [HHToastTool show:@"点击更多"];
    };
    
    row = [self addRowUser:userModel];
    
    [section addFormRow:row];

    section = [XLFormSectionDescriptor formSection];
    [form addFormSection:section];
    
    row = [self rowWithTitle:@"开始"];
    [section addFormRow:row];
    
    row = [self rowSwitchWithTitle:@"切换"];
    
    row.onChangeBlock = ^(id  _Nullable oldValue, id  _Nullable newValue, XLFormRowDescriptor * _Nonnull rowDescriptor) {
        BOOL open = [rowDescriptor.value boolValue];
        [HHToastTool show:open?@"打开":@"关闭"];
    };
    [section addFormRow:row];
    
    row = [self rowArrowWithTitle:@"相册" viewControllerClass:nil];
    [section addFormRow:row];
    
    row = [self rowArrowWithTitle:@"收藏" detail:@"有了" viewControllerClass:nil];
    [section addFormRow:row];
    
    section = [XLFormSectionDescriptor formSection];
    [form addFormSection:section];
    
    row = [self rowArrowWithTitle:@"开始了" detail:@"有了" viewControllerClass:nil];
    [section addFormRow:row];
    
    section = [XLFormSectionDescriptor formSection];
    [form addFormSection:section];
    row = [self rowButtonWithTitle:@"退出" color:[UIColor redColor]];
    row.action.formBlock = ^(XLFormRowDescriptor * _Nonnull sender) {
        [self reloadFormRow:sender];
        [HHToastTool show:sender.title];
    };
    
    [section addFormRow:row];

    self.form = form;
}

@end
